package stephen.competition13;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class OpenShop
 */
public class OpenShop extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public OpenShop() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		
		String username=request.getParameter("username");
		String shopname=request.getParameter("shopName");
		System.out.println("username="+username+"   shopName="+shopname);
		
		if(username!=""&&shopname!=""){	 //不等于 	
		   
			UserService us=new UserService();
		    
		    boolean result=false;        
		  try {
			result=us.openShop(shopname,username);
			
		  } catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();       
		  }
		    if(result){
			response.sendRedirect("aaShopRegisterSuccess.html");
		    }
		    else{
			response.sendRedirect("aaShopRegisterFail.html");
		    }
		}
		else{
			response.sendRedirect("aaShopRegisterFail.html");
	}	
		
		
		
		
	//	response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
